﻿using System;
using System.Data.SqlClient;
using System.Windows.Forms;
using DataCenter.Interface;
using DataCenter.Interface.Model;

namespace DataCenter.Component.Calculator
{
    [Calculator("ArithmeticCalculator", "1.0.0.1", 
        "基本算术运算计算器，可以进行“+”、“-”、“*”、“//”、“(”、“)”的运算")]
    public class ArithmeticCalculatorEntity : ComponentEntity
    {
        public ArithmeticCalculatorEntity()
        {
            base.ComponentType = ComponentTypes.Calculator;
        }

        public override bool Create(SqlCommand command)
        {
            DefaultEditForm editForm = new DefaultEditForm(this, false);
            if (editForm.ShowDialog() == DialogResult.OK)
            {
                //base.ComponentConfig = ToXml().OuterXml;
                Insert(command);
                return true;
            }
            return false;
        }

        public override bool Modify(SqlCommand command)
        {
            DefaultEditForm editForm = new DefaultEditForm(this, true);
            if (editForm.ShowDialog() == DialogResult.OK)
            {
                base.ComponentConfig = ToXml().OuterXml;
                Update(command);
                return true;
            }
            return false;
        }

        public override TComponent CreateComponent<TComponent>(SqlCommand command)
        {
            ICalculator component = new ArithmeticCalculator(command, this);
            return (TComponent)component;
        }
    }
}
